package com.utopia.keyvalue.store;

import junit.framework.TestCase;

/**
 * @author yanjiaqiang
 * @date 2011-3-21
 * @version $Id: StorageTest.java 5 2011-03-22 09:23:42Z JiaqiangYan@gmail.com $
 */
public abstract class StorageTest extends TestCase {

	public abstract Storage newStorage();

	public void testFunction() {
		Storage storage = newStorage();

		storage.put("a", "abc".getBytes());
		assertEquals("abc", new String(storage.get("a")));

		storage.putIfAbent("a", "bbb".getBytes());
		assertEquals("abc", new String(storage.get("a")));

		storage.remove("a");
		storage.putIfAbent("a", "bbb".getBytes());
		assertEquals("bbb", new String(storage.get("a")));

		for (int i = 0; i < 1000; i++) {
			storage.put(i + "", (i + "").getBytes());
		}

		assertEquals(storage.size(), 1001);

		for (int i = 0; i < 1000; i++) {
			byte[] value = storage.get(i + "");
			assertEquals(new String(value), (i + ""));
		}

		storage.close();

	}

	public void testPersistence() {

	}

}
